import com.cowcode.util.Util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2021/6/22
 * Time: 18:41
 * To change this template use File | Settings | File Templates.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext.xml")
public class test01 {



    @Test
    public void Test01(){
        String code = Util.codeNum();
        String address = "https://yiketianqi.com/api/sms?appid=56923216&appsecret=g1Hh7esa&code="+code+"&mobile=13023904387&template_id=103";
        try {
            crawler(address);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private String crawler(String address) throws IOException {//爬虫方法
        InputStream in = null;
        InputStreamReader reader = null;
        URLConnection con = null;
        BufferedReader br = null;
        String result = "";
        try {
            URL url = new URL(address);//地址
            con = url.openConnection();
            in = con.getInputStream();
            reader = new InputStreamReader(in,"utf-8");
            br = new BufferedReader(reader);
            String s1 = "";
            while((s1=br.readLine())!=null) {
                result+=s1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(reader!=null) reader.close();
            if(in!=null) in.close();
        }
        return result;
    }
}
